﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace iLangl.LanguageWire
{
	public class LanguageWireConfiguration : ConfigurationSection
	{
		private static ConfigurationProperty authKeyProperty;

		private static ConfigurationProperty originalCompanyIdProperty;
		private static ConfigurationProperty priceMatrixCompanyIdProperty;

		private static ConfigurationProperty currencyIdProperty;
		private static ConfigurationProperty countryIdProperty;

		private static ConfigurationProperty enforceAgitoTranslateProperty;
		private static ConfigurationProperty permitAgitoTranslateProperty;


		//Responsible persons
		private static ConfigurationProperty responsibleAmIdProperty;
		private static ConfigurationProperty responsiblePmIdProperty;
		private static ConfigurationProperty responsibleOfficeIdProperty;

		//Customer Propertirs
		private static ConfigurationProperty customerOriginProperty;

		//Billing Information
		private static ConfigurationProperty billingCountryIdProperty;
		private static ConfigurationProperty billingCompanyNameProperty;
		private static ConfigurationProperty billingFirstNameProperty;
		private static ConfigurationProperty billingLastNameProperty;
		private static ConfigurationProperty billingEmailProperty;
		private static ConfigurationProperty billingStreetAddressProperty;
		private static ConfigurationProperty billingPostalCodeProperty;
		private static ConfigurationProperty billingCityProperty;

		private static LanguageWireConfiguration instance;
		private static ConfigurationPropertyCollection properties;

		static LanguageWireConfiguration()
		{
			authKeyProperty = new ConfigurationProperty(
			  "authKey",
			  typeof(String),
			  null,
			  ConfigurationPropertyOptions.IsRequired);

			originalCompanyIdProperty = new ConfigurationProperty(
			  "originalCompanyId",
			  typeof(String),
			  null,
			  ConfigurationPropertyOptions.IsRequired);

			priceMatrixCompanyIdProperty = new ConfigurationProperty(
			  "priceMatrixCompanyId",
			  typeof(String),
			  null,
			  ConfigurationPropertyOptions.IsRequired);

			currencyIdProperty = new ConfigurationProperty(
			  "currencyId",
			  typeof(String),
			  null,
			  ConfigurationPropertyOptions.IsRequired);

			countryIdProperty = new ConfigurationProperty(
			  "countryId",
			  typeof(String),
			  null,
			  ConfigurationPropertyOptions.IsRequired);

			responsibleAmIdProperty = new ConfigurationProperty(
			  "responsibleAmId",
			  typeof(String),
			  null,
			  ConfigurationPropertyOptions.IsRequired);

			responsiblePmIdProperty = new ConfigurationProperty(
			  "responsiblePmId",
			  typeof(String),
			  null,
			  ConfigurationPropertyOptions.IsRequired);

			responsibleOfficeIdProperty = new ConfigurationProperty(
			  "responsibleOfficeId",
			  typeof(String),
			  null,
			  ConfigurationPropertyOptions.IsRequired);

			customerOriginProperty = new ConfigurationProperty(
			  "customerOrigin",
			  typeof(String),
			  null,
			  ConfigurationPropertyOptions.IsRequired);

			enforceAgitoTranslateProperty = new ConfigurationProperty(
			  "enforceAgitoTranslate",
			  typeof(String),
			  null,
			  ConfigurationPropertyOptions.IsRequired);

			permitAgitoTranslateProperty = new ConfigurationProperty(
			  "permitAgitoTranslate",
			  typeof(String),
			  null,
			  ConfigurationPropertyOptions.IsRequired);

			//Billing

			billingCountryIdProperty = new ConfigurationProperty(
			  "billingCountryId",
			  typeof(String),
			  null,
			  ConfigurationPropertyOptions.IsRequired);

			billingCompanyNameProperty = new ConfigurationProperty(
			  "billingCompany",
			  typeof(String),
			  null,
			  ConfigurationPropertyOptions.IsRequired);

			billingFirstNameProperty = new ConfigurationProperty(
			  "billingFirstName",
			  typeof(String),
			  null,
			  ConfigurationPropertyOptions.IsRequired);
			billingLastNameProperty = new ConfigurationProperty(
			  "billingLastName",
			  typeof(String),
			  null,
			  ConfigurationPropertyOptions.IsRequired);
			billingEmailProperty = new ConfigurationProperty(
			  "billingEmail",
			  typeof(String),
			  null,
			  ConfigurationPropertyOptions.IsRequired);
			billingStreetAddressProperty = new ConfigurationProperty(
			  "billingStreetAddress",
			  typeof(String),
			  null,
			  ConfigurationPropertyOptions.IsRequired);
			billingPostalCodeProperty = new ConfigurationProperty(
			  "billingPostalCode",
			  typeof(String),
			  null,
			  ConfigurationPropertyOptions.IsRequired);
			billingCityProperty = new ConfigurationProperty(
			  "billingCity",
			  typeof(String),
			  null,
			  ConfigurationPropertyOptions.IsRequired);

			properties = new ConfigurationPropertyCollection();
			properties.Add(authKeyProperty);
			properties.Add(originalCompanyIdProperty);
			properties.Add(priceMatrixCompanyIdProperty);
			properties.Add(currencyIdProperty);
			properties.Add(countryIdProperty);


			properties.Add(customerOriginProperty);

			properties.Add(responsibleAmIdProperty);
			properties.Add(responsiblePmIdProperty);
			properties.Add(responsibleOfficeIdProperty);

			properties.Add(enforceAgitoTranslateProperty);
			properties.Add(permitAgitoTranslateProperty);

			properties.Add(billingCountryIdProperty);
			properties.Add(billingCompanyNameProperty);
			properties.Add(billingFirstNameProperty);
			properties.Add(billingLastNameProperty);
			properties.Add(billingEmailProperty);
			properties.Add(billingStreetAddressProperty);
			properties.Add(billingPostalCodeProperty);
			properties.Add(billingCityProperty);
		}

		private static object mutex = new object();
		/// <summary>
		/// The instance of the TransportConfiguration.
		/// </summary>
		public static LanguageWireConfiguration Instance
		{
			get
			{
				if (instance == null)
				{
					lock (mutex)
					{
						if (instance == null)
						{
							instance = ConfigurationManager.GetSection("LanguageWireConfiguration") as LanguageWireConfiguration;
						}
					}
				}
				return instance;
			}
		}

		public Int32 CountryId
		{
			get
			{

				return Int32.Parse(base[countryIdProperty] as String);
			}
		}

		public Int32 CurrencyId
		{
			get
			{

				return Int32.Parse(base[currencyIdProperty] as String);
			}
		}

		public Int32 OriginalCompanyId
		{
			get
			{

				return Int32.Parse(base[originalCompanyIdProperty] as String);
			}
		}

		public Int32 CustomerOrigin
		{
			get
			{

				return Int32.Parse(base[customerOriginProperty] as String);
			}

		}
		

		public Int32 PriceMatrixCompanyId
		{
			get
			{

				return Int32.Parse(base[priceMatrixCompanyIdProperty] as String);
			}
		}

		public String ResponsibleAMId
		{
			get
			{

				return base[responsibleAmIdProperty] as String;
			}
		}

		public String ResponsiblePMId
		{
			get
			{

				return base[responsiblePmIdProperty] as String;
			}
		}

		public Int32 ResponsibleOfficeId
		{
			get
			{

				return Int32.Parse(base[responsibleOfficeIdProperty] as String);
			}
		}


		public bool EnforceAgitoTranslate 
		{
			get
			{

				return bool.Parse(base[enforceAgitoTranslateProperty] as String);
			}
		}

		public bool PermitAgitoTranslate
		{
			get
			{

				return bool.Parse(base[permitAgitoTranslateProperty] as String);
			}
		}

		#region Billing
		public Int32 BillingCountryId
		{
			get
			{
				return Int32.Parse(base[billingCountryIdProperty] as String);
			}
		}

		public String BillingCompanyName
		{
			get
			{
				return base[billingCompanyNameProperty] as String;
			}
		}


		public String BillingFirstName
		{
			get
			{
				return base[billingFirstNameProperty] as String;
			}
		}

		public String BillingLastName
		{
			get
			{
				return base[billingLastNameProperty] as String;
			}
		}

		public String BillingEmail
		{
			get
			{
				return base[billingEmailProperty] as String;
			}
		}

		public String BillingStreetAddress
		{
			get
			{
				return base[billingStreetAddressProperty] as String;
			}
		}

		public String BillingPostalCode
		{
			get
			{
				return base[billingPostalCodeProperty] as String;
			}
		}

		public String BillingCity
		{
			get
			{
				return base[billingCityProperty] as String;
			}
		}
		#endregion



		public String AuthKey
		{
			get
			{

				return base[authKeyProperty] as String;
			}
		}

		protected override ConfigurationPropertyCollection Properties
		{
			get
			{
				return properties;
			}
		}
	}
}